package lt.egidijus.aatest.junit;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.internal.junit.util.TestSearchEngine;


/**
 * The class uses restricted {@link TestSearchEngine} to test if the given type
 * is a JUnit class.
 * 
 *  Rafal Korytkowski
 */
@SuppressWarnings("restriction")
public class JUnitEngine {
	public static boolean isJUnit(IType type) {
		try {
			return TestSearchEngine.isTestOrTestSuite(type);
		} catch (CoreException e) {
			return false;
		}
	}
	
	public static boolean isJUnitTestSuite(IType type) {
		try {
			if (TestSearchEngine.isTestOrTestSuite(type)){
				IAnnotation[] anotations = type.getAnnotations();
				for (IAnnotation anotation : anotations){
					if (anotation.getElementName().contains("Suite.")){
						return true;
					}
				}
			}
		} catch (CoreException e) {
			return false;
		}
		return false;
	}
}
